﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XChipMatlab
{
    
    using MathWorks.MATLAB.NET.Arrays;
    using MathWorks.MATLAB.NET.Utility;
    using XChipNr3dAccutate;
    using XChipNr3dFast;

    public class XChipNr3d
    {

        Nr3dFast nr3dF;
        Nr3dAccutate nr3dA;
     
        public XChipNr3d() {
            nr3dF = new Nr3dFast();
            nr3dA = new Nr3dAccutate();
           
        }

        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }
        /// <summary>
        /// 初略标定
        /// </summary>
        /// <param name="filter_en"></param>
        /// <param name="image_cols"></param>
        /// <param name="image_rows"></param>
        /// <param name="weight_lid"></param>
        /// <param name="bits_raw"></param>
        /// <param name="noise_x_node"></param>
        /// <param name="noise_y_node"></param>
        /// <param name="ratio_up"></param>
        /// <param name="ratio_step"></param>
        /// <param name="image_path_src"></param>
        /// <param name="image_path_dst"></param>
        /// <param name="paramter_path"></param>
        /// <returns></returns>
        public string[] Nr3dFastGen(int filter_en, int image_cols, int image_rows, int weight_lid, int bits_raw, int[] noise_x_node, int[] noise_y_node, double ratio_up, double ratio_step, string image_path_src, string image_path_dst, string paramter_path) {
            string[] strList = new string[5];
            ///判断文件路劲是否存在 不存在则添加
            if (false == System.IO.Directory.Exists(image_path_dst.ToString()))
            {
                System.IO.Directory.CreateDirectory(image_path_dst.ToString());
            }
            if (false == System.IO.Directory.Exists(paramter_path.ToString() + "v1"))
            {
                System.IO.Directory.CreateDirectory(paramter_path.ToString() + "v1");
            }
            if (false == System.IO.Directory.Exists(paramter_path.ToString() + "v2"))
            {
                System.IO.Directory.CreateDirectory(paramter_path.ToString() + "v2");
            }
            //var fList =  ftest.main_fast(5, (MWNumericArray)filter_en, (MWNumericArray)image_cols, (MWNumericArray)image_rows, (MWNumericArray)weight_lid, (MWNumericArray)bits_raw, (MWNumericArray)noise_x_node, (MWNumericArray)noise_y_node, (MWNumericArray)ratio_up, (MWNumericArray)ratio_step, image_path_src, image_path_dst, paramter_path);
            var nr3dArr = nr3dF.main_fast(5, (MWNumericArray)filter_en, (MWNumericArray)image_cols, (MWNumericArray)image_rows, (MWNumericArray)weight_lid, (MWNumericArray)bits_raw, (MWNumericArray)noise_x_node, (MWNumericArray)noise_y_node, (MWNumericArray)ratio_up, (MWNumericArray)ratio_step, image_path_src, image_path_dst, paramter_path);
            for (int i = 0; i < nr3dArr.Count(); i++)
            {
                strList[i] = nr3dArr[i].ToString();
            }

            //for (int i = 0; i < fList.Count(); i++)
            //{
            //    strList[i] = fList[i].ToString();
            //}
            return strList;
        }
        /// <summary>
        /// 精确标定
        /// </summary>
        /// <param name="filter_en"></param>
        /// <param name="image_cols"></param>
        /// <param name="image_rows"></param>
        /// <param name="weight_lid"></param>
        /// <param name="bits_raw"></param>
        /// <param name="noise_x_node"></param>
        /// <param name="noise_y_node"></param>
        /// <param name="gain_sel"></param>
        /// <param name="ratio_th"></param>
        /// <param name="image_path_src"></param>
        /// <param name="image_path_dst"></param>
        /// <param name="paramter_path"></param>
        /// <returns></returns>
        public string[] Nr3dAccutateGen(int filter_en, double image_cols, double image_rows, double weight_lid, double bits_raw, int[] noise_x_node, int[] noise_y_node, string gain_sel, double ratio_th, string image_path_src, string image_path_dst, string paramter_path) {
            string[] strList = new string[3];
            ///判断文件路劲是否存在 不存在则添加
            if (false == System.IO.Directory.Exists(image_path_dst.ToString()))
            {
                System.IO.Directory.CreateDirectory(image_path_dst.ToString());
            }
            if (false == System.IO.Directory.Exists(paramter_path.ToString() + "v1"))
            {
                System.IO.Directory.CreateDirectory(paramter_path.ToString() + "v1");
            }
            if (false == System.IO.Directory.Exists(paramter_path.ToString() + "v2"))
            {
                System.IO.Directory.CreateDirectory(paramter_path.ToString() + "v2");
            }
            var nr3daArr = nr3dA.main_accurate(3, filter_en, image_cols, image_rows, weight_lid, bits_raw, (MWNumericArray)noise_x_node, (MWNumericArray)noise_y_node, (MWCharArray)gain_sel, ratio_th, image_path_src, image_path_dst, paramter_path);
            for (int i = 0; i < nr3daArr.Count(); i++)
            {
                strList[i] = nr3daArr[i].ToString();
            }
            return strList;
        }
    }
}
